﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CMS.BLL;


public partial class Controls_Products_ctrPackage : System.Web.UI.UserControl
{
     private int nCurrentLang = Support.GetCurrentLanguage();
    private int nDefaultLanguage = Support.GetDefaultLanguage();
 
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.BindProduct();
        }
    }

    private void BindProduct()
    {
        int nCurentLanguage = Support.GetCurrentLanguage();
        switch (nCurentLanguage )
        {
            case 1:
                lblPackage.Text = "Gói tư vấn trực tuyến"; 
                break;
            case 2:
                lblPackage.Text = "Online Consutancy Package "; 
                break;
            case 3:
                lblPackage.Text = "Online Consutancy Package "; 
                break;
        }
        int nPagecount = 0;
        Products objProduct = new Products();
        DataTable dtbProduct = new DataTable();
        dtbProduct = objProduct.Search(0, "", "", 0, "", 0, 0, 0, 100000000, -1,-1, 1, 0, 0, 0, nDefaultLanguage, nCurrentLang, 1, 5, ref nPagecount);
        dtlPackage.DataSource = dtbProduct;
        dtlPackage.DataBind();
    }
    protected void dtlPackage_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        int nCurentLanguage = Support.GetCurrentLanguage();
        if ((e.Item.ItemType != ListItemType.Header) && (e.Item.ItemType != ListItemType.Footer))
        {
            HyperLink lnkName = (HyperLink)e.Item.FindControl("lnkName");
            Label lblPrice = (Label)e.Item.FindControl("lblPrice");
            HyperLink lnkFeatures = (HyperLink)e.Item.FindControl("lnkFeatures");

            int nID = ConvertData.ConvertToInt(DataBinder.Eval(e.Item.DataItem, "ProductID"));

            lnkName.ImageUrl = Config.ROOT + Config.IMAGE_PRODUCT_DEFAULT_UPLOAD + ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "ImageDefault"));
           lnkName.NavigateUrl = Config.ROOT + Pages.FrontEnds.PRODUCT_DETAIL + "?" + Config.PRO_ID + "=" + nID ;
          
           switch (nCurentLanguage)
           {
               case 1:
                   lblPrice.Text = Support.FormatCurrency(DataBinder.Eval(e.Item.DataItem, "Price")) + " " + "₫/tháng";
                   break;
               case 2:
                   lblPrice.Text = Support.FormatCurrency(DataBinder.Eval(e.Item.DataItem, "Price")) + " " + "₫/month";
                   break;
               case 3:
                   lblPrice.Text = Support.FormatCurrency(DataBinder.Eval(e.Item.DataItem, "Price")) + " " + "₫/month";
                   break;
           }
           string sContent = ConvertData.ConvertToString(DataBinder.Eval(e.Item.DataItem, "MainContent"));
            if(sContent.Length >173)
            {
                sContent = ConvertData.TruncateString(sContent, 173) + Config.DOT  ; 
            }

            lnkFeatures.Text = sContent;
          
        }
    }
}
